using System.Diagnostics;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;

namespace Catchbase.TestTools
{
	[TestClass]
    public abstract class TestBase<TSubject> where TSubject : class
    {
        private Dependencies<TSubject> _dependencies;
        private Subject<TSubject> _subject;

        protected TSubject Subject
        {
            get
            {
                Debug.Assert(_subject != null, "Did you overide TestInitialize instead of InitializeTest?");
                return _subject.Instance;
            }
        }

        [TestInitialize]
        public virtual void TestInitialize()
        {
            _dependencies = new Dependencies<TSubject>();
            InitializeTest();
            _subject = new Subject<TSubject>(_dependencies.Objects);
        }

	    protected abstract void InitializeTest();

        protected virtual Mock<T> FuncMock<T>() where T : class
        {
            _dependencies.SetFuncInjection(Mock<T>().Object);
            return Mock<T>();
        }

        protected virtual Mock<T> Mock<T>() where T : class
        {
            return _dependencies.GetMock<T>();
        }
    }
}